package com.smartjobs.model;

import com.smartjobs.bean.CourseBean;
import com.smartjobs.util.DBManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;

public class CourseModel {

	public static void getAllCourses(ArrayList<CourseBean> courseList,
			int trainerId) {

		String query = "select * from smartjobs.course where trainerId = "
				+ trainerId;
		ResultSet result = DBManager.selectFromDB(query);
		try {
			while (result.next()) {
				CourseBean course = new CourseBean();
				course.setCost(result.getString("cost"));
				course.setCourseID(result.getInt("courseId"));
				course.setCourseName(result.getString("courseName"));
				course.setDescription(result.getString("description"));
				course.setNoOfMonths(result.getString("noOfMonths"));				
				courseList.add(course);
			}
		} catch (SQLException e) {
			
			e.printStackTrace();
		}
	}

	public static void insertCourse(CourseBean course) {

		String query = "insert into smartjobs.course "
				+ "(courseName, description, noOfMonths, cost, trainerId) values ('"
				+ course.getCourseName() + "','" + course.getDescription()
				+ "','" + course.getNoOfMonths() + "','" + course.getCost()
				+ "','" + course.getTrainerId() + "')";

		System.out.println(query);

		DBManager.insertIntoDB(query);
	}

	public static void deleteCourse(int courseId) {
		String query = "delete from smartjobs.course where courseId= "
				+ courseId;
		DBManager.deleteFromDB(query);
	}
}
